package pcloud.client.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Date;

public class Logger
{
	public static String logFilePathName = null;
	static File file;

	public static void write(String log, String type)
	{
		if (logFilePathName == null) {
			logFilePathName = GlobalConfig.getInstance().getProperty("logFile");
			file = new File(logFilePathName);
			if (file.exists()) {
				file.delete();
			}
		}

		try {
			OutputStreamWriter streamWriter= new OutputStreamWriter(
							new FileOutputStream(file,true), "UTF-8");
			//FileWriter不能指定输出文件的编码, 用OutputStreamWriter代替
//			streamWriter = new FileWriter(file, true);

			String logText = new Date() + " (" + type + ") " + log
					+ System.getProperty("line.separator");
			streamWriter.write(logText);
			streamWriter.flush();
			streamWriter.close();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	public static void write(String log)
	{
		write(log, "Info");
	}
}
